<?php
class inman_ctl_admin_commission extends desktop_controller{
	public function __construct($app){
		parent::__construct($app);
		$this->model=app::get('inman')->model('commission');
		$this->CheckData=kernel::single('inman_commission_object');
	}
	public function index(){
		$this->finder('inman_mdl_commission',array(
			'title'=>app::get('inman')->_('佣金列表'),
			'actions'=>array(
				array(
						'label'=>app::get('inman')->_('添加佣金'),
						'href'=>'index.php?app=inman&ctl=admin_commission&act=add',
						'target'=>'dialog::{title:\''.app::get('inman')->_('添加佣金').'\',width:800,height:500,}',
						),
				),
	        'use_buildin_tagedit'=>true,//标签管理
	        'use_buildin_set_tag'=>true,
	        'use_buildin_export'=>true,//导出
	        'use_buildin_import'=>true,//导入
	        'use_buildin_recycle'=>true,//删除
	        'allow_detail_popup'=>true,
			));
	}
	public function add(){
		$this->display('admin/commission/add.html');
	}
	public function toAdd(){
		if(!empty($_POST['com'])){
			$this->begin();
			$com=$_POST['com'];
			if(!$this->CheckData->checkName($com['com_name'],$smg)){
				$this->end(false,$smg);
			}
			if(!$this->CheckData->checkPercentage($com['com_percentage'],$smg)){
				$this->end(false,$smg);
			}
			$com['add_time']=time();
			$com['update_time']=time();
			$this->end($this->model->save($com),app::get('inman')->_('添加成功'));
		}
	}
	//编辑佣金规则
	public function edit(){
		if(!empty($_POST['com'])){
			//var_dump($_POST['com']);die;
			$com=$_POST['com'];
			$this->begin('index.php?app=inman&ctl=admin_commission&act=index');//刷新
			//检测名称
			if(!$this->CheckData->checkName($com['com_name'],$smg,$com['com_id'])){
				$this->end(false,$smg);
			}
			//检查佣金比例
			if(!$this->CheckData->checkPercentage($com['com_percentage'],$smg)){
				$this->end(false,$smg);
			}
			$com['update_time']=time();
			$this->end($this->model->save($com),app::get('inman')->_('编辑成功'));
		}
	}
	//佣金管理tab
	public function _views(){
		return array(
				1=>array('label'=>app::get('inman')->_('所有'),'optional'=>false,'filter'=>array()),
				2=>array('label'=>app::get('inman')->_('启用'),'optional'=>false,'filter'=>array('status'=>'1')),
				3=>array('label'=>app::get('inman')->_('禁用'),'optional'=>false,'filter'=>array('status'=>'0')),
				
		);
	}
}